package com.jeethink.web.controller.gs;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jeethink.common.annotation.Log;
import com.jeethink.common.enums.BusinessType;
import com.jeethink.gs.domain.GsCompany;
import com.jeethink.gs.service.GsCompanyService;
import com.jeethink.common.core.controller.BaseController;
import com.jeethink.common.core.domain.AjaxResult;
import com.jeethink.common.utils.poi.ExcelUtil;
import com.jeethink.common.core.page.TableDataInfo;

/**
 * 公司Controller
 * 
 * @author jeethink
 * @date 2022-08-10
 */
@Controller
@RequestMapping("/gs/company")
public class GsCompanyController extends BaseController
{
    private String prefix = "gs/company";

    @Autowired
    private GsCompanyService gsCompanyService;

    @RequiresPermissions("system:company:view")
    @GetMapping()
    public String company()
    {
        return prefix + "/company";
    }

    /**
     * 查询公司列表
     */
    @RequiresPermissions("system:company:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GsCompany gsCompany)
    {
        startPage();
        List<GsCompany> list = gsCompanyService.selectGsCompanyList(gsCompany);
        return getDataTable(list);
    }

    /**
     * 导出公司列表
     */
    @RequiresPermissions("system:company:export")
    @Log(title = "公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GsCompany gsCompany)
    {
        List<GsCompany> list = gsCompanyService.selectGsCompanyList(gsCompany);
        ExcelUtil<GsCompany> util = new ExcelUtil<GsCompany>(GsCompany.class);
        return util.exportExcel(list, "company");
    }

    /**
     * 新增公司
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存公司
     */
    @RequiresPermissions("system:company:add")
    @Log(title = "公司", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(GsCompany gsCompany)
    {
        return toAjax(gsCompanyService.insertGsCompany(gsCompany));
    }

    /**
     * 修改公司
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        GsCompany gsCompany = gsCompanyService.selectGsCompanyById(id);
        mmap.put("gsCompany", gsCompany);
        return prefix + "/edit";
    }

    /**
     * 修改保存公司
     */
    @RequiresPermissions("system:company:edit")
    @Log(title = "公司", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GsCompany gsCompany)
    {
        return toAjax(gsCompanyService.updateGsCompany(gsCompany));
    }

    /**
     * 删除公司
     */
    @RequiresPermissions("system:company:remove")
    @Log(title = "公司", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gsCompanyService.deleteGsCompanyByIds(ids));
    }

    /**
     * 根据id获取公司
     * @author Hyunjin
     * @date 14:26 2022/8/10
     * @return com.jeethink.common.core.domain.AjaxResult
     **/
    @GetMapping("/selectExecutor")
    @ResponseBody
    public List<Map<String,Object>> selectExecutor(){
        System.out.println(gsCompanyService.selectExecutor());
        return gsCompanyService.selectExecutor();
    }
}
